package com.gp.controller;

import com.gp.util.CommonResult;
import com.gp.entity.AdvertisePosition;
import com.gp.service.AdvertisePositionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/marketing/position")
public class AdvertisePositionController {
    @Resource
    private AdvertisePositionService positionService;

    @GetMapping("/findAll")
    public CommonResult findAll(Integer page, Integer limit, AdvertisePosition advertisePosition) {
        return positionService.findAll(page, limit, advertisePosition);

    }

    //根据id删除
    @DeleteMapping("/del")
    public CommonResult delete(Integer id) {
        return positionService.deleteById(id);
    }

    //修改
    @PutMapping("/update")
    public CommonResult update(Long id, Integer type, String name, String descrition, Integer maxCount) {
        AdvertisePosition position = new AdvertisePosition();
        position.setId(id);
        position.setType(type);
        position.setName(name);
        position.setDescrition(descrition);
        position.setMaxCount(maxCount);
        return positionService.updateById(position);
    }

    //添加
    @PostMapping("/add")
    public CommonResult add(AdvertisePosition advertisePosition) {
        AdvertisePosition position = new AdvertisePosition();
        position.setName(advertisePosition.getName());
        position.setType(advertisePosition.getType());
        position.setDescrition(advertisePosition.getDescrition());
        position.setMaxCount(advertisePosition.getMaxCount());
        return positionService.insert(position);
    }


}
